package com.itheima;

import com.itheima.pojo.User;
import com.opencsv.CSVReader;


import java.io.FileReader;
import java.text.SimpleDateFormat;


/**
 * @author wmh
 * @version 1.0 2022/6/4
 * @Description: CSV读取百万数据
 **/
public class CSVDemo {
    private static SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
    public static void main(String[] args) throws Exception {
        CSVReader csvReader = new CSVReader(new FileReader("百万数据.csv"));
        //读到第一行，是小标题
        String[] title = csvReader.readNext();
        User user = null;
        while (true){
            user = new User();
            String[] content = csvReader.readNext();
            if(content == null){
                break;
            }
            user.setId(Long.parseLong(content[0]));
            user.setUserName(content[1]);
            user.setPhone(content[2]);
            user.setHireDate(simpleDateFormat.parse(content[3]));
            user.setAddress(content[4]);
            System.out.println(user);
        }
    }
}